-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disallow function pointers to #[rustc_args_required_const] #48078
Disallow function pointers to #[rustc_args_required_const] #48078
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
r? @eddyb Thanks again for your excellent instructions here! To confirm we at least don't need this for stdsimd today in terms of methods, just free functions for intrinsics. (methods may come at a later date maybe though?) |
src/librustc_typeck/check/mod.rs
Outdated
span: Span) { | ||
// We're only interested in functions tagged with | ||
// #[rustc_args_required_const], so ignore anything that's not. | ||
if !self.tcx.get_attrs(def_id).iter().any(|a| a.check_name("rustc_args_required_const")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be !self.tcx.has_attr(def_id, "rustc_args_required_const")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed!
Unfortunately left out it means that when the `#![feature(proc_macro)]` flag is in effect it fails to find `rustc_args_required_const` for expansion. This version, however, is verified to work with stdsimd's requirements!
ba31f4f
to
b5475af
Compare
@alexcrichton Oh, what I was thinking wrt methods is irrelevant - you can't "extract" the method as a value any other way than using a value path - so your check here would work fine even then. |
} | ||
|
||
self.tcx.sess.span_err(span, "this function can only be invoked \ | ||
directly, not through a function pointer"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you generalize this a bit?
Some context: foo(0)
works but let f = foo; f(0)
doesn't, even if it doesn't become a function pointer (if we allow the latter, we can't prevent let f = foo; f(0); f(1)
easily/at all, which is the scary hazard, typesystem-wise).
So, "this function can only be called directly, not used as a value or called through a function pointer".
half an hour later okay maybe we can just keep your version, if it's confusing for anyone we can change it later.
@alexcrichton Okay, I think the only change I want on this is a sanity check in case we screw up: rust/src/librustc_trans/mir/rvalue.rs Lines 195 to 197 in 932c736
rust/src/librustc_trans/mir/constant.rs Lines 714 to 716 in 932c736
rust/src/librustc_mir/interpret/eval_context.rs Lines 716 to 718 in 932c736
Those 3 places implement the reification to a |
b5475af
to
5de8e19
Compare
📌 Commit 5de8e19 has been approved by |
This commit disallows acquiring a function pointer to functions tagged as `#[rustc_args_required_const]`. This is intended to be used as future-proofing for the stdsimd crate to avoid taking a function pointer to any intrinsic which has a hard requirement that one of the arguments is a constant value.
5de8e19
to
7a20fc1
Compare
@bors: r=eddyb |
📌 Commit 7a20fc1 has been approved by |
…-proc-macro, r=eddyb Disallow function pointers to #[rustc_args_required_const] This commit disallows acquiring a function pointer to functions tagged as `#[rustc_args_required_const]`. This is intended to be used as future-proofing for the stdsimd crate to avoid taking a function pointer to any intrinsic which has a hard requirement that one of the arguments is a constant value. Note that the first commit here isn't related specifically to this feature, but was necessary to get this working in stdsimd!
@bors: rollup |
…-proc-macro, r=eddyb Disallow function pointers to #[rustc_args_required_const] This commit disallows acquiring a function pointer to functions tagged as `#[rustc_args_required_const]`. This is intended to be used as future-proofing for the stdsimd crate to avoid taking a function pointer to any intrinsic which has a hard requirement that one of the arguments is a constant value. Note that the first commit here isn't related specifically to this feature, but was necessary to get this working in stdsimd!
…-proc-macro, r=eddyb Disallow function pointers to #[rustc_args_required_const] This commit disallows acquiring a function pointer to functions tagged as `#[rustc_args_required_const]`. This is intended to be used as future-proofing for the stdsimd crate to avoid taking a function pointer to any intrinsic which has a hard requirement that one of the arguments is a constant value. Note that the first commit here isn't related specifically to this feature, but was necessary to get this working in stdsimd!
This commit disallows acquiring a function pointer to functions tagged as
#[rustc_args_required_const]
. This is intended to be used as future-proofingfor the stdsimd crate to avoid taking a function pointer to any intrinsic which
has a hard requirement that one of the arguments is a constant value.
Note that the first commit here isn't related specifically to this feature, but was necessary to get this working in stdsimd!